//
//  YTLoginController.m
//  YUNT
//
//  Created by haha on 2017/11/11.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTLoginController.h"
#import "YTLoginIconView.h"
#import "ZYXUserNetManager.h"
#import "UIView+Toast.h"

@interface YTLoginController ()
@property (weak, nonatomic) IBOutlet UITextField *accountTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UIButton *loginButton;
@property (weak, nonatomic) IBOutlet UIButton *forgetButton;
@property (weak, nonatomic) IBOutlet UIButton *liscenceButton;

@end

@implementation YTLoginController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar setHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = Language(@"登录");
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"rf_back"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    
    [self initSubviews];
}

- (void)initSubviews
{
    self.loginButton.layer.cornerRadius = 20;
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:Language(@"登录即同意")];
    
    [attString addAttribute:NSForegroundColorAttributeName
                      value:[UIColor blackColor]
                      range:NSMakeRange(0, attString.length)];
    
    NSMutableAttributedString *attString1 = [[NSMutableAttributedString alloc] initWithString:Language(@"软件许可及服务协议")];
    
    [attString1 addAttribute:NSForegroundColorAttributeName
                       value:[UIColor colorWithRed:162/255.0f green:69/255.0f blue:163/255.0f alpha:1.0f]
                       range:NSMakeRange(0, attString1.length)];
    
    [attString appendAttributedString:attString1];
    
    [attString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0f] range:NSMakeRange(0, attString.length)];
    
    [self.liscenceButton setAttributedTitle:attString forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)goBack
{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)loginButtonAction:(UIButton *)sender
{
    NSString *userMobile = _accountTextField.text;
    
    if (userMobile.length < 1)//密码几位数
    {
        [KeyWindow makeToast:Language(@"密码不能为空")];
        
        return;
    }
    
    [ZYXUserNetManager userLoginAccount:_accountTextField.text Pw:_passwordTextField.text Success:^(NSDictionary *data, NSInteger status) {
        //TODO:SAVESTATUS
        [self goBack];
    } Fail:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
